nginx 通过请求中的关键字跳转

如果需要从客户端发过来的请求中判断是否含有某些关键字,根据关键字再另做处理,则可以在server块中另入这样配置,判断$request_uri:

location/ {

proxy_passhttp://backend;

#当请求中包含有”123,abc,你好”,关键字时,则跳转到另一个服务http://192.168.0.105

if ($request_uri  ~* =(123|abc|你好|)){

proxy_passhttp://192.168.0.105;

}

}


或者跳转到指定的本地页面,当请求中是index.php或者是index.jsp时,跳转至html目录:

location/index.php{

root  html;

}

location/index.jsp{

root  html;

}

当请求中含有 *.php时,跳转至html目录

location~*.php{

root  html;

}


该文章对你有帮助吗,求分享转发: 分享到QQ空间 分享给QQ好友

 

 

粤ICP备19116230号
友情链接: 码农藏书阁 天天链